/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gob.cgr.sgrh.ejb.entidad;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author MICROSOF
 */
@Entity
@Table(name = "dato_familiar")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatoFamiliar.findAll", query = "SELECT d FROM DatoFamiliar d"),
    @NamedQuery(name = "DatoFamiliar.findByIdDatoFamiliar", query = "SELECT d FROM DatoFamiliar d WHERE d.idDatoFamiliar = :idDatoFamiliar"),
    @NamedQuery(name = "DatoFamiliar.findByVive", query = "SELECT d FROM DatoFamiliar d WHERE d.vive = :vive"),
    @NamedQuery(name = "DatoFamiliar.findByParentezco", query = "SELECT d FROM DatoFamiliar d WHERE d.parentezco = :parentezco")})
public class DatoFamiliar implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_DATO_FAMILIAR")
    private Integer idDatoFamiliar;
    @Size(max = 1)
    @Column(name = "VIVE")
    private String vive;
    @Size(max = 45)
    @Column(name = "PARENTEZCO")
    private String parentezco;
    @JoinColumn(name = "ID_PERSONAL", referencedColumnName = "ID_PERSONAL")
    @ManyToOne(optional = false)
    private Personal idPersonal;
    @JoinColumn(name = "ID_PERSONA", referencedColumnName = "ID_PERSONA")
    @ManyToOne(optional = false,cascade=CascadeType.MERGE)
    private Persona idPersona;
   
    @ManyToOne()
    @JoinColumns(value = {@JoinColumn(name = "parentezco" , referencedColumnName = "id_maestra", insertable=false,updatable=false )})//, @JoinColumn(name = "state_code", referencedColumnName = "iso_code")})
    private Maestra tipoParentezco;
    
    public DatoFamiliar() {
    }

    public DatoFamiliar(Integer idDatoFamiliar) {
        this.idDatoFamiliar = idDatoFamiliar;
    }

    public Integer getIdDatoFamiliar() {
        return idDatoFamiliar;
    }

    public void setIdDatoFamiliar(Integer idDatoFamiliar) {
        this.idDatoFamiliar = idDatoFamiliar;
    }

    public String getVive() {
        return vive;
    }

    public void setVive(String vive) {
        this.vive = vive;
    }

    public String getParentezco() {
        return parentezco;
    }

    public void setParentezco(String parentezco) {
        this.parentezco = parentezco;
    }

    public Personal getIdPersonal() {
        return idPersonal;
    }

    public void setIdPersonal(Personal idPersonal) {
        this.idPersonal = idPersonal;
    }

    public Persona getIdPersona() {
        return idPersona;
    }

    public void setIdPersona(Persona idPersona) {
        this.idPersona = idPersona;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idDatoFamiliar != null ? idDatoFamiliar.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatoFamiliar)) {
            return false;
        }
        DatoFamiliar other = (DatoFamiliar) object;
        if ((this.idDatoFamiliar == null && other.idDatoFamiliar != null) || (this.idDatoFamiliar != null && !this.idDatoFamiliar.equals(other.idDatoFamiliar))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gob.cgr.sgrh.ejb.entidad.DatoFamiliar[ idDatoFamiliar=" + idDatoFamiliar + " ]";
    }

    
    @Transient
	public Maestra getTipoParentezco() {
		return tipoParentezco;
	}
    @Transient
	public void setTipoParentezco(Maestra tipoParentezco) {
		this.tipoParentezco = tipoParentezco;
		this.parentezco=tipoParentezco.getValor();
	}
    
}
